package com.atguigu1.one;

/**
 * ClassName: ontArrayTest
 * Package: com.atguigu1.one
 * Description:
 *
 * @Author BuTang
 * @Create 2023/2/22 19:05
 * @Version 1.0
 */
public class oneArrayTest  {
    public static void main(String args[]) {
        //1.数组的声明与初始化
        //声明数组
        //静态初始化 ： 数组变量的赋值和 数组元素的赋值一同进行
        double[] prices = new double[]{20.32, 43.21, 43.22};

        //动态初始化 ： 数组变量的赋值和数组元素的赋值是分开进行的
        // String[ ] foods = new String[]{"拌海蜇","龙须菜 ","玉兰片","鱼香肉丝"};;
        String[] foods ;
        foods = new String[4];

        //其他方式
        int arr[] = new int[3];
        int[] arr1 = {1, 2, 3};//类型 推断
        int[] arr3;
        arr3 =new int[4];

        //2.数组元素的调用
        //通过角标的方式，获取数组的元素,角标的范围是 0 -数组的范围-1
        System.out.println(prices[0]);
        System.out.println(foods[0]);

        foods[0] = "拌海蜇";
        foods[1] = "龙须菜";
        foods[2] = "玉兰片";
        foods[3] = "鱼香肉丝";

        //3.数组的长度 用来数组容器中容量的大小
        //用length表示
        System.out.println(foods.length);//4

        //4.如何遍历数组
        for (int i = 0 ; i < foods.length ; i ++){
            System.out.println(foods[i]);

        }


    }
}
